package org.duiduo.config;

import ch.qos.logback.core.PropertyDefinerBase;
import org.springframework.boot.system.ApplicationHome;
import org.springframework.stereotype.Component;

import java.io.File;

/**
 * 日志存储配置类
 *
 * @author liangze
 * @date 2023/1/13 13:23
 */
@Component
public class LogDirConfig extends PropertyDefinerBase {

    /**
     * 日志存放位置
     */
    private String LOG_HOME;

    /**
     * 获取jar包位置
     *
     * @return
     */
    @Override
    public String getPropertyValue() {
        ApplicationHome h = new ApplicationHome(getClass());
        File jarF = h.getSource();
        if (jarF == null) {
            // 单元测试跑到 logs 文件夹下
            return h + "/logs";
        }
        this.LOG_HOME = jarF.getParentFile().toString() + "/logs";
        return this.LOG_HOME;
    }
}
